package com.oracle.Service;

import com.oracle.Service.impl.CategoryService;
import com.oracle.dao.impl.CategoryDao;
import com.oracle.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryDao categoryDao;

    @Override
    public String insertByCategory(Category category) {
        //如果插入的类型为空
        if (category==null){
            return "NO";
        }
        //如果插入的类型名和描述为空或者“”则显示插入失败
        if (category.getCname()==null||category.getCname().equals("")||category.getDescription()==null||category.getDescription().equals("")){
            return "NO";
        }
        categoryDao.insertByCategory(category);
        return "YES";
    }

    @Override
    public List<Category> selectCategorys() {
        List<Category> list = categoryDao.selectCategorys();
        if (list==null){
            return null;
        }
        return list;
    }

    @Override
    public List<Category> selectCategorys_All() {
        List<Category> list = categoryDao.selectCategorys_All();
        if (list==null){
            return null;
        }
        return list;
    }

    @Override
    public String updateByCid(Category record) {
        String result = categoryDao.updateByCid(record);
        if (result.equals("NO")){
            return "NO";
        }
        return "YES";
    }

    @Override
    public String deleteByPrimaryKey(Category category) {
        String result = categoryDao.deleteByPrimaryKey(category.getCid());
        if (result.equals("NO")){
            return "NO";
        }
        return "YES";
    }
}
